﻿using QLKetNoi;
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLDVu.BO
{
    public class BaoCaoNoBO
    {
        public static void ThemBaoNo(string mabaocaono,string thangbaocao)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<BAOCAONOTIEN> baocaono = dulieu.GetTable<BAOCAONOTIEN>();
            BAOCAONOTIEN x = new BAOCAONOTIEN();
            x.MaBaoCao = mabaocaono;

            x.ThangBaoCao =Convert.ToDateTime(thangbaocao);

            baocaono.InsertOnSubmit(x);
            dulieu.SubmitChanges();

        }
        public static void ThemChiTietBaoNo(string machitiet, string mabaocaono,string makhachhang,string nodau,string nocuoi,string nophatsinh)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<CHITIETBAOCAONO> baocaono = dulieu.GetTable<CHITIETBAOCAONO>();
            CHITIETBAOCAONO x = new CHITIETBAOCAONO();
            x.MaChiTiet = machitiet;
            x.MaBaoCao = mabaocaono;
            x.MaKhachHang = makhachhang;
            x.NoDau =Convert.ToInt32(nodau);
            x.NoCuoi =Convert.ToInt32(nocuoi);
            x.NoPhatSinh =Convert.ToInt32(nophatsinh);

            baocaono.InsertOnSubmit(x);
            dulieu.SubmitChanges();

        }
        public static BAOCAONOTIEN BaoCaoNoCuoiCung()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            BAOCAONOTIEN s = dulieu.BAOCAONOTIENs.OrderByDescending(dv => dv.MaBaoCao).FirstOrDefault();
            return s;

        }
        public static CHITIETBAOCAONO ChiTietBaoCaoNoCuoiCung()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            CHITIETBAOCAONO s = dulieu.CHITIETBAOCAONOs.OrderByDescending(dv => dv.MaChiTiet).FirstOrDefault();
            return s;

        }
       
        public static void XoaChiTietBaoCao(string mabaocao)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<CHITIETBAOCAONO> chitietbaocaono = dulieu.GetTable<CHITIETBAOCAONO>();
            var dschitietbcn = from ct in chitietbaocaono
                               where ct.MaBaoCao.Equals(mabaocao)
                               select ct;
            chitietbaocaono.DeleteAllOnSubmit(dschitietbcn);
            dulieu.SubmitChanges();
        }

       
    }
}
